package com.goomba.batch;

import com.goomba.demo.contants.Commons;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;

public class Consumer {

    public static void main(String[] args) throws Exception {
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("batch_consumer_group");

        consumer.setNamesrvAddr(Commons.nameSrvAddr);

        consumer.subscribe("batch_topic", "TAG1");

        consumer.registerMessageListener((MessageListenerConcurrently) (list, consumeConcurrentlyContext) -> {

            System.out.println("list" + list.size());
            for (MessageExt ext : list) {
                System.out.println("获取的数据是" + new String(ext.getBody()));
            }
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        });

        consumer.start();


    }
}
